package org.cug.service.impl;

import org.cug.mapper.InternshipTeachingMapper;
import org.cug.mapper.UserMapper;
import org.cug.pojo.InternshipTeaching;
import org.cug.pojo.User;
import org.cug.service.InternshipTeachingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class InternshipTeachingTeachingServiceimpl implements InternshipTeachingService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private InternshipTeachingMapper internshipTeachingMapper;

    @Override
    public List<InternshipTeaching> list(Integer userId) {
        User user = userMapper.getrole(userId);
        List<Integer> ids = new ArrayList<>();
        if (user.getRole().equals("1")) {
            ids.add(userId);
        } else if (user.getRole().equals("2")) {
            ids = userMapper.getusers(user.getDepartment());
        }else if(user.getRole().equals("3")){
            ids = userMapper.getuserscol(user.getCollege());
        }else {
            List<InternshipTeaching> internshipTeachings = internshipTeachingMapper.listAll();
            return internshipTeachings;
        }
        List<InternshipTeaching> internshipTeachings = internshipTeachingMapper.list(ids);
        return internshipTeachings;
    }

    @Override
    public void add(InternshipTeaching internshipTeaching) {
        internshipTeachingMapper.insert(internshipTeaching);
    }

    @Override
    public void delete(List<Integer> ids) {
        internshipTeachingMapper.delete(ids);
    }

    @Override
    public InternshipTeaching selectid(Integer id) {
        return internshipTeachingMapper.select(id);
    }

    @Override
    public void alterbyid(InternshipTeaching internshipTeaching) {
        internshipTeachingMapper.update(internshipTeaching);
    }
}
